package Reflect;

import domain.Person;

import java.lang.reflect.Method;

/**
 * @Author: ylc
 * @Description:
 * @Date Created in 2022-04-19 15:37
 */
public class ReflectDemo3 {
    public static void main(String[] args) throws Exception{
        Class personCls = Person.class;
        /* 获取成员方法们：
			* Method[] getMethods()
			* Method getMethod(String name, 类<?>... parameterTypes)

			* Method[] getDeclaredMethods()
			* Method getDeclaredMethod(String name, 类<?>... parameterTypes)
         */
        //获取无参方法
        Method eat = personCls.getMethod("eat");
        Person p = new Person();
        //获取有参方法
        Method eat1 = personCls.getMethod("eat", String.class);
        //执行方法
        eat.invoke(p);
        eat1.invoke(p,"food");



    }


}
